package com.PTRS.dao;

import com.PTRS.entities.User;
import org.apache.ibatis.annotations.*;

import java.util.List;


public interface IUserDao {
    //查询所有
    @Select("SELECT * FROM user")
    @Results(
            id = "userMap",value = {
                    @Result(id = true,column = "user_id",property = "userID"),
                    @Result(column = "user_passwd",property = "userPasswd"),
                    @Result(column = "user_nickname",property = "userNickname"),
                    @Result(column = "user_sex",property = "userSex"),
                    @Result(column = "is_member",property = "isMember"),
                    @Result(column = "user_balance",property = "userBalance"),
                    @Result(column = "user_email",property = "userEmail"),
                    @Result(column = "user_tel",property = "userTel"),
                    @Result(column = "user_age",property = "userAge")
    }
    )
    List<User> findAll();

    //插入用户
    @Insert("INSERT INTO consumer(user_id, user_passwd, user_nickname, user_sex, is_member, user_balance, user_email, user_tel, user_age) VALUES (#{userID},#{userPasswd},#{userNickname},#{userSex},#{isMember},#{userBalance},#{userEmail},#{userTel},#{userAge})")
    void saveUser(User user);

    //更新用户
    @Update("UPDATE consumer SET user_id=#{userID},user_passwd=#{userPasswd},user_nickname=#{userNickname},user_sex=#{userSex},is_member=#{isMember},user_balance=#{userBalance},user_email=#{userEmail},user_tel=#{userTel},user_age=#{userAge} WHERE user_id=#{userID}")
    void updateUser(User user);

    //删除操作
    @Delete("DELETE FROM consumer WHERE user_id=#{userID}")
    void deleteUser(String userID);

    //查询单个，参数为user的id
    @Select("SELECT * FROM consumer WHERE user_id=#{userID}")
    @ResultMap("userMap")
    User findUserByID(String userID);
}
